package com.Hwadee.educms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.Hwadee.educms.entity.CrmBanner;
import com.Hwadee.educms.entity.vo.BannerVo;
import com.Hwadee.educms.mapper.CrmBannerMapper;
import com.Hwadee.educms.service.CrmBannerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author 677
 * @since 2021-07-08
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {

    @Cacheable(value = "banner", key = "'selectIndexBanner'")//缓存,注意加单引号
    @Override
    //查询所有banner
    public List<CrmBanner> selectAllBanner() {
        QueryWrapper<CrmBanner> wrapper = new QueryWrapper<>();
        wrapper.orderByAsc("id")
               .last("limit 3");
        List<CrmBanner> list = baseMapper.selectList(wrapper);
        return list;
    }


    //2.添加banner
    @Override
    public void saveBanner(BannerVo bannerVo) {
        CrmBanner banner = new CrmBanner();
        BeanUtils.copyProperties(bannerVo, banner);
        baseMapper.insert(banner);
    }

    //2.更新banner
    @Override
    public void updateBanner(BannerVo bannerVo) {
        CrmBanner banner = new CrmBanner();
        BeanUtils.copyProperties(bannerVo, banner);
        baseMapper.updateById(banner);
    }
}
